package com.ysh.dao.system;

import com.ysh.domain.system.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;
/*
    部门dao层接口
 */
public interface DeptMapper {

    // 保存(添加功能)
    @Insert("insert into ss_dept (dept_id, dept_name, parent_id, state) values(#{id},#{deptName},#{parentId},#{state})")
    int save(Dept dept);

    // 根据id查询
    @Select("select dept_id, dept_name, parent_id, state from ss_dept where dept_id=#{id}")
    @Results({
            @Result(id = true,column = "dept_id",property = "id"),
            @Result(column = "dept_name",property = "deptName"),
            @Result(column = "parent_id",property = "parentId"),
            @Result(column = "state",property = "state"),
            @Result(property = "parent", javaType=Dept.class,column = "parent_id",
                    one=@One(select="com.ysh.dao.system.DeptMapper.findById")
            )
    })
    Dept findById(String id);

    // 查询所有
    @Select("select dept_id, dept_name, parent_id, state from ss_dept")
    @Results({
            @Result(id = true,column = "dept_id",property = "id"),
            @Result(column = "dept_name",property = "deptName"),
            @Result(column = "parent_id",property = "parentId"),
            @Result(column = "state",property = "state"),
            @Result(property = "parent", javaType=Dept.class,column = "parent_id",
                    one=@One(select="com.ysh.dao.system.DeptMapper.findById")
            )
    })
    List<Dept> findAll();

    // 删除
    @Delete("delete from ss_dept where dept_id=#{id}")
    int delete (Dept dept);

    // 修改
    @Update("update ss_dept set dept_name=#{deptName},parent_id=#{parentId},state=#{state} where dept_id=#{id}")
    int update(Dept dept);

}
